package models

import (
	"fmt"
	"log"
)

type User struct {
	ID       int    `gorm:"primary_key" json:"id"`
	Username string `json:"username"`
	Password string `json:"password"`
	Nickname string `json:"nickname"`
	Avatar   string `json:"avatar"`
	Status   int    `json:"status"`
}

func CheckAuth(username, password string) bool {
	var auth User
	db.Select("id").Where(User{Username: username}).First(&auth)
	if auth.ID > 0 {
		return true
	}
	return false
}

// 增加用户
func AddAuth(username string, password string) {
	auth := User{
		Username: username,
		Password: password,
	}
	a := db.Create(&auth)
	fmt.Println(a, "sssssss")
	//fmt.Println(a == true, "sssssss")
}

//获取指定用户

func GetAuth(username string, password string) map[string]interface{} {
	var auth User
	data := make(map[string]interface{})

	db.Select("nickname", "avatar").Where(User{Username: username}).First(&auth)
	data["nickname"] = auth.Nickname
	data["avatar"] = auth.Avatar
	log.Println(data)
	return data
}
